<?php /* УТФ-8:fix */

class SPIview__media__manage /* extends SPIview__media */
{
    public function render_item( $item_title, $data )
    {
        $tpl = SPItpl::I('manage');

        $tpl->assign_by_ref('SPIcfg', SPIcfg::as_array() );
        $tpl->assign_by_ref('item_title', $item_title);
        $tpl->assign_by_ref('data', $data);
        $tpl->assign('mode', 'item');

        return $tpl->compile('media/manager.item.tpl');
    }

    public function render_form( $item_title, $data )
    {
        $tpl = SPItpl::I('manage');

        $tpl->assign_by_ref('SPIcfg', SPIcfg::as_array() );
        $tpl->assign_by_ref('item_title', $item_title);
        $tpl->assign_by_ref('data', $data);
        $tpl->assign('mode', 'form');

        return $tpl->compile('media/manager.item.tpl');
    }

    public function json_action_response( $media_group_id, $div_id, $status, $result_data = null )
    {
        $response = array();
        $response['media_group_id'] = $media_group_id;
        $response['div_id']         = $div_id;
        $response['status']         = $status;

        switch( $status )
        {
            case 'complite':
            case 'delete_complite':
            {
                $response['content'] = $result_data;
                break;
            }

            case 'error':
            {
                $response['error_messages'] = is_array( $result_data ) ? $result_data : array( $result_data );
                break;
            }
        }

        SPIv::I('json')->render($response);
        return true;
    }
}
